<?php
/**
 * app端 返回新鸿基商家信息列表
 * Author: lyun
 * Date: 2019/3/12
 * Created by Panxsoft.
 */


namespace App\Http\Controllers\App\SunHungKai;

use App\Http\Controllers\ApiController;
use App\Models\Admin\CustomerCompany;
use App\Models\Customer\DeviceAccount;
use App\Services\Utils\Guard;
use Illuminate\Database\Eloquent\Collection;

class CompanyManageController extends ApiController
{
    const ROUTES = [
        'index' => 'api.app.sun.hung.kai.company.manage.index'
    ];

    /**
     * @return array|\Illuminate\Http\Response
     * @throws \App\Exceptions\ApiAbstractException
     */
    public function index()
    {
        /** @var DeviceAccount $device_account */
        $device_account = Guard::deviceAccount();
        $customer = $device_account->customer;
            $this->checkIsTrue(($customer->isSunHungKai()), trans('admin.is_specify_customer_id'));

        /** @var Collection $customer_companies */
        $customer_companies = CustomerCompany::where('customer_id', $customer->id)->get();

//        $customer_companies = $customer_companies->groupBy('category_id')->values();

        return $this->response(compact('customer_companies'));
    }
}
